package observers;

import java.util.ArrayList;
import java.util.List;

public class FileEventPublisher {
    private static FileEventPublisher instance = null;

    private List<Observer> observers = new ArrayList<>();

    private FileEventPublisher() {}

    public static synchronized FileEventPublisher getInstance() {
        if (instance == null) {
            instance = new FileEventPublisher();
        }
        return instance;
    }

    public void attach(Observer observer) {
        if (!observers.contains(observer)) {
            observers.add(observer);
        }
    }

    public void detach(Observer observer) {
        observers.remove(observer);
    }

    public void notifyObservers( String message) {
        for (Observer observer : observers) {
            observer.update(message);
        }
    }
}

